package com.agileplex.products.acc;

import java.util.Stack;
import java.util.Iterator;

/**
 * ACC session stack.
 *
 * @creator Rui Tang
 * @date 2008-06-14
 *
 * @LastChanged
 * @LastChangedBy $LastChangedBy: tangrui@agileplex.com $
 * @LastChangedDate $LastChangedDate: 2008-06-20 13:52:50 +0000 (Fri, 20 Jun 2008) $
 * @LastChangedRevision $LastChangedRevision: 2 $
 */
public class SessionStack {

    private static SessionStack singleton = new SessionStack();

    private Stack<Session> stack = new Stack<Session>();

    private SessionStack() {
    }

    public static SessionStack getSingleton() {
        return singleton;
    }

    public void push(Session session) {
        this.stack.push(session);
    }

    public void pop() {
        this.stack.pop();
    }

    public String getPrompt() {
        StringBuffer sb = new StringBuffer();

        for (Iterator<Session> it = this.stack.iterator(); it.hasNext(); ) {
            Session session = it.next();
            sb.append(session.getPrompt());
            if (it.hasNext()) {
                sb.append(Constants.DEFAULT_PROMPT_SEPARATOR);
            }
        }

        return sb.toString();
    }

    public String getDedicatedPrompt() {
        return this.getPrompt() + Constants.DEFAULT_PROMPT_TERMINATOR;
    }

}
